using System;
using System.ComponentModel;
using System.Globalization;
using System.ComponentModel.Design.Serialization;



namespace Camalon.Drawing
{
	public class ReadOnlyObjectConverter: ExpandableObjectConverter
	{
		public override bool CanConvertFrom(ITypeDescriptorContext context, 	Type sourceType) 
		{
			if (sourceType == typeof(string)) return true;
			return base.CanConvertFrom(context, sourceType);
		}

		public override object ConvertFrom(ITypeDescriptorContext context, 	CultureInfo culture, object value) 
		{
			if (value is string) return context.PropertyDescriptor.GetValue( context.Instance );
			return base.ConvertFrom(context, culture, value);
		}

		public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) 
		{  
			if (destinationType == typeof(string) ) return "("+ context.PropertyDescriptor.Name +")";
			return base.ConvertTo(context, culture, value, destinationType);
		}
	}

}


